{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = './lena.jpg'\n",
    "img = cv.imread(filename)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "cv.imshow('Hello, world!', img)\n",
    "cv.waitKey()\n",
    "cv.destroyAllWindows()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)\n",
    "# print(hsv.shape)\n",
    "cv.imshow(\"Hue\", hsv[:, :, 0])\n",
    "cv.imshow(\"Saturation\", hsv[:, :, 1])\n",
    "cv.imshow(\"Value\", hsv[:, :, 2])\n",
    "cv.waitKey()\n",
    "cv.destroyAllWindows()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "cv.imshow(\"Blue: \", img[:, :, 0])\n",
    "cv.imshow(\"Green: \", img[:, :, 1])\n",
    "cv.imshow(\"Red: \", img[:, :, 2])\n",
    "cv.waitKey()\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 原图与HSV三种空间显示图对比\n",
    "- Hue代表色相，按照色相轮中的位置，红色为0，显示为偏白色，黄色等其他颜色偏深色。从lena的帽子上可以看出来\n",
    "- saturation代表饱和度，如lena的嘴唇、帽子上蓝色羽毛都是饱和度较高的区域，显示为深色；而lena的头发是深棕色，显示为浅色\n",
    "- value代表亮度，即彩色图片转为黑白图片后的颜色，lena的脸显示为浅色，头发显示为深色"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
